package com.snail.snailvr.views.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.snail.snailvr.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by snail on 16/4/19.
 */
public class HomePageAdapter extends FragmentPagerAdapter {
    public static final int TAB_LOCAL=0/*TAB_WEB=1*/,TAB_INPUT=1;
    private final List<Fragment> mFragments = new ArrayList<>();
    private List<Integer> mFragmentIcons = new ArrayList<>();
    private Context mContext;

    public HomePageAdapter(Context context,FragmentManager fm) {
        super(fm);
        mContext=context;
    }

    public void addFragment(Fragment fragment, int resId) {
        mFragments.add(fragment);
        mFragmentIcons.add(resId);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    public View getTabView(int position) {
        View tab = LayoutInflater.from(mContext).inflate(R.layout.tabbar_view, null);
        ImageView tabImage = (ImageView) tab.findViewById(R.id.tab_icon);
        if(tabImage!=null)
            tabImage.setImageResource(mFragmentIcons.get(position));
        if (position == 0) {
            tab.setSelected(true);
        }
        return tab;
    }
}
